<?php

namespace App\Admin\Actions\Goods;

use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;


class GoodsBatchOnShelf extends BatchAction
{

    protected $selector = '.on-shelf';

    public $name = '<a class=\'on-shelf btn btn-sm btn-info\'><i class=\'fa fa-info-circle\'></i>&nbsp;批量启用</a>';

    public function handle(Collection $collection)
    {
        try {
            foreach ($collection as $model) {
                $model->status = 1;
                $model->save();
            }
            return $this->response()->success('启用成功')->refresh();

        } catch (Exception $e) {
            return $this->response()->error('产生错误：'.$e->getMessage());
        }

    }

    public function dialog()
    {
        $this->confirm('您确定启用选中的商品吗？');
    }

}